import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { cacheConf } from '@conf/cache.conf';
import { SFComponent, SFSchema, SFUISchema } from '@delon/form';
import { EACacheService } from '@shared';
import { NzModalService } from 'ng-zorro-antd/modal';
import { BankCardManagementService } from '../../../services/bank-card-management.service';

interface EmitType {
  success: boolean,
  current: number,
  value: object
};
@Component({
  selector: 'app-cwc-bank-card-management-add',
  templateUrl: './add.component.html',
  styleUrls: ['./add.component.less']
})
export class CwcBankCardManagementAddComponent implements OnInit {
  schema: SFSchema = {};
  ui: SFUISchema = {};
  record: any;
  i: any;
  userInfo: any = {};
  bankBranchName = '';
  bankArea = '';
  bankName = '';
  loading = false;
  current = 0; // 当前节点
  verifyInfo = {};
  steps: Array<any> = [
    {
      id: 1,
      title: `绑定银行卡`,
      async: false,
      percentage: null
    },
    {
      id: 2,
      title: `小额鉴权`,
      async: false,
      percentage: null
    },
    {
      id: 3,
      title: `完成`,
      async: false,
      percentage: null
    },
  ];

  @ViewChild('sf', { static: false }) sf!: SFComponent;
  networkTransporterId = '';
  bankSfInfo: any = {} // 银行卡信息;
  smallAuthentication: any = {}; //小额鉴权信息

  branchBanks: any[] = [];
  constructor(public service: BankCardManagementService,
    public modalService: NzModalService, public router: Router,
    public ar: ActivatedRoute, public eaCacheSrv: EACacheService) {
    this.networkTransporterId = this.eaCacheSrv.get(cacheConf.env)?.networkTransporterId
  }


  ngOnInit() {

  }

  trackById(_: number, item: any): number {
    return item.id;
  }



  formatCard() {
    return /[1-9]\d{12,18}/;
  }

  changeCurrent(e: EmitType) {
    if (e && e?.success) {
      this.current = e?.current;
      if (this.current === 1) {
        this.bankSfInfo = e?.value;
      }
    }
  }
  toBandCardPage() {
    this.router.navigate(['../index'], {
      relativeTo: this.ar
    });
  }

}
